home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / cbm / 1249 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: ci.pwr.wroc.pl!sco!st103
  2. From: st103@sco.zsi.pwr.wroc.pl (A Member of Elysium)
  3. Newsgroups: comp.sys.cbm
  4. Subject: Re: PROGRAMMING- MUL's DIV's
  5. Date: 25 Jan 1996 13:37:49 GMT
  6. Organization: Technical Univeristy of Wroclaw
  7. Message-ID: <4e813d$aoi@sun1000.pwr.wroc.pl>
  8. References: <4e5dp2$m4i@sun1000.pwr.wroc.pl> <4e5q5p$ekt@news.acns.nwu.edu>
  9. NNTP-Posting-Host: sco.zsi.pwr.wroc.pl
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. B
  13. Stephen Judd (judd@merle.acns.nwu.edu) wrote:
  14. : In article <4e5dp2$m4i@sun1000.pwr.wroc.pl>,
  15. : A Member of Elysium <st103@sco.zsi.pwr.wroc.pl> wrote:
  16. : >Hi!
  17. : >
  18. : >I'm going to write some math stuff for my c64 byt i have a little problem:
  19. : >i need a 16 bits * 16 bits multiplication program and 16 bits / 8 bits or 8 bits / 8 bits division program that will return not the integer and fractional part of the number. I dont expect ANY optimized solutions i just wan a basic version that is slow but works. Can any one help me? Aspecialy with the division ?
  20. : >
  21. : >Kris
  22. : >
  23.  
  24. : Straightforward 16-bit routines, coming right up:
  25.  
  26. : *------------------------
  27.  
  28. : * 16-bit Multiply routine
  29.  
  30. : * ACC*AUX -> [ACC,EXT] (low,hi) 32-bit result
  31.  
  32. : MULT    LDA #0
  33. :     STA EXT+1
  34. :     LDY #$11
  35. : ]LOOP    LSR EXT+1
  36. :     ROR
  37. :     ROR ACC+1
  38. :     ROR ACC
  39. :     BCC MUL2
  40. :     CLC
  41. :     ADC AUX
  42. :     PHA
  43. :     LDA AUX+1
  44. :     ADC EXT+1
  45. :     STA EXT+1
  46. :     PLA
  47. : MUL2    DEY
  48. :     BNE ]LOOP
  49. :     STA EXT
  50. :     RTS
  51.  
  52. : * Divide routine
  53.  
  54. : * ACC/AUX -> ACC, remainder in EXT
  55.  
  56. : DIV    LDA #0
  57. :     STA EXT+1
  58. :     LDY #$10
  59. : ]LOOP    ASL ACC
  60. :     ROL ACC+1
  61. :     ROL
  62. :     ROL EXT+1
  63. :     PHA
  64. :     CMP AUX
  65. :     LDA EXT+1
  66. :     SBC AUX+1
  67. :     BCC DIV2
  68. :     STA EXT+1
  69. :     PLA
  70. :     SBC AUX
  71. :     PHA
  72. :     INC ACC
  73. : DIV2    PLA
  74. :     DEY
  75. :     BNE ]LOOP
  76. :     STA EXT
  77. :     RTS
  78.  
  79. : Note that I did not write these; I lifted them off the Merlin assembler disk.
  80. : They work just like you would write one: you have two numbers, A and B.  
  81. : Multiply A by each power of two contained in B.  They are the most efficient
  82. : implementation of this that I have seen though (if you want to make it just
  83. : a little faster, change PLA/PHA to TXA/TAX, or store ACC in X, etc.).
  84.  
  85. :     evetS
  86.  Ok. i'm very satisfied with muls routine but  ineed abit different divisin routine. it returns me the integer part of the results and the REST if i understood good.. but i need it to return me the rest in such a format: 
  87. f.e.
  88.  
  89. 5 div 2 = 2 and 128 
  90.                 ---
  91.                 256
  92.  
  93. 7 div 3 = 2 and  85
  94.                  ---
  95.                  256
  96.  
  97. have you got the point?? But thanx for thesr routines !!! i will certainly use them.
  98.  
  99. Kris.
  100.  
  101. p.s. ANY other postings on this subject are VERY welcome
  102.  
  103.               
  104.  -
  105.